package com.polaris.live.adapter.party

import android.view.View
import com.blankj.utilcode.util.StringUtils
import com.blankj.utilcode.util.TimeUtils
import com.bumptech.glide.Glide
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.common.ext.convertArabicDigitsToNormal
import com.polaris.live.databinding.AdapterMemberNewBinding
import com.polaris.live.resp.back_resp.PartyRecentlyMemberResp
import com.polaris.live.translation.R
import com.polaris.live.utils.image.ImageUtils
import com.polaris.live.utils.image.normal
import com.polaris.live.widget.avatar.FrameImageUtils

/**
 * RoomInfoMemberNowAdapter 房间最近加入的成员
 *
 * @author Created by 天晴 on 2024/9/25/004 12:03
 */
class RoomInfoMemberNowAdapter : BaseBindingAdapter<AdapterMemberNewBinding, PartyRecentlyMemberResp>() {

    init {
        addChildClickViewIds(com.polaris.live.R.id.av_fv)
    }

    override fun convert(holder: VBViewHolder<AdapterMemberNewBinding>, item: PartyRecentlyMemberResp) {
        val user = item.user
        holder.vb.apply {
            Glide.with(context).load(ImageUtils.imgPathSmall(user.avatar)).normal().into(followItemHead)
            followItemNickName.text = user.nickname
            avFv.setFrameImage(FrameImageUtils.urlToFrameImageBean(user.avatarFrame))

            if (item.user.country?.isBlank() == true) {
                cvCountry.visibility = View.GONE
            } else {
                cvCountry.visibility = View.VISIBLE
                cvCountry.setCountry(item.user.country)
            }
            vipView.setVipLevel(item.user.vipLevel)
            sexView.setSexAndAge(item.user.sex, item.user.birthday)
            languageView.setLanguage(item.user.secondLanguage)
            myLevel.setRichsLevel(item.user.richs)
            myLevel2.setCharmsLevel(item.user.charms)
            llFlag.setLabel(item.user.label)
            if (item.price > 0) {
                coinImg.visibility = View.VISIBLE
                //0Diamonds 1Beans 4gameCoin
                when (item.coinType) {
                    0L -> {
                        coinImg.setImageResource(com.polaris.live.R.drawable.diamond)
                    }

                    1L -> {
                        coinImg.setImageResource(com.polaris.live.R.drawable.anchor_ic_beans)
                    }

                    2L -> {
                        coinImg.setImageResource(com.polaris.live.R.drawable.ic_game_beans)
                    }
                }
                tvCoin.text = "${item.price}"
            } else {
                coinImg.visibility = View.GONE
                tvCoin.text = StringUtils.getString(R.string.free)
            }
            tvTime.text = TimeUtils.millis2String(item.createTime.toLongOrNull() ?: 0, "yyyy.MM.dd HH:mm:ss")
                .convertArabicDigitsToNormal()
        }
    }

}